#include "service_arch/service_arch.h"
#include "service_arch/service_base_impl.h"
#include "database/simple_db_pool.h"
#include "base/logging.h"

#include "FavoriteService_types.h"
#include "FavoriteService_constants.h"
#include "FavoriteService.h"

#include <iostream>
#include <map>
#include <boost/detail/atomic_count.hpp>

#include <thrift/concurrency/Mutex.h>
#include <thrift/concurrency/TimerManager.h>

#include "redis_executor/redis_executor.h"
#include "redis_executor/scoped_reply.h"

using namespace std;
using namespace apache::thrift;

namespace jztzp {

class ReloadRedisTask;

class FavoriteServiceHandler : public FavoriteServiceIf, public ServiceBaseImpl {
  friend class ReloadRedisTask;
 public:
  FavoriteServiceHandler();

  virtual ~FavoriteServiceHandler();

  virtual int32_t Add(const int32_t member, const int32_t article);
  virtual int32_t Remove(const int32_t member, const int32_t article);
  virtual void GetMemberFavoriteArticles(std::vector<int32_t> & _return, const int32_t member);
  virtual void GetArticleFavoriteMembers(std::vector<int32_t> & _return, const int32_t article);

  bool ReloadRedis();
 private:
  bool AddRedis(int32_t member, int32_t article);

  base::SimpleConnectionPool db_pool_; 
  RedisExecutor redis_exec_;
  concurrency::TimerManager timer_manager_;
};

}

